﻿using OSSUtility;
using OSSUtility.Communicate;
using Ozone.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;


namespace Ozone.Device
{
    public class DevBase11
    {
        protected Session session_;
        public bool bIsConn { get; set; } = false;

        //失败次数
        public int nFaildTime { get; set; } = 0;

        public bool bTryConn { get; set; } = false;

        public object objLock { get; set; } = new object();

        public delegate void DelegateDeviceFun(string tag, bool bSwitchFlag);


        public DelegateDeviceFun DelegateDeviceFun_;


        public DevBase11(CommCfg cfg)
        {
            if (cfg.CommType == "0")
                session_ = new Session(cfg.IP, cfg.Port);
            else
                session_ = new Session(cfg.Port, Utility.str2int(cfg.Baud));
        }
        //com
        public DevBase11(string port, int baud = 9600)
        {
            session_ = new Session(port, baud);
        }

        //TCP
        public DevBase11(string FSrvIP, string FPort)
        {
            session_ = new Session(FSrvIP, FPort);
        }

        public bool Open()
        {
            bIsConn = session_.ConnSrv();
            return bIsConn;
        }

        public void Close()
        {
            session_.DisConn();
        }
    }
}
